package com.guwu.compress_image_uploading.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileUtil {
    public static File getFilePath(Context context) {
        File outDir = null;
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            //判断状态，保存到sd卡中公有目录（根目录）的pictures文件夹下
            outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        } else {
            if (context != null) {
                //保存安装包下的文件夹中
                outDir = context.getFilesDir();
            }
        }
        if (!outDir.exists()) {
            outDir.mkdirs();
        }
        return outDir;
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        return formatter.format(curDate); //转化为字符串
    }

    /**
     * 获取当前时间图片
     *
     * @param context
     * @return
     */
    public static File getDateFile(Context context) {
        return new File(getFilePath(context), getDate() + ".jpg");
    }


}
